import json

from django.shortcuts import *
from django.http import *
from stu.models import Stu
from django.core import serializers


def index(request):
    a = Stu.objects.filter(name__startswith='李', age__range=[10, 30])
    # Stu.objects.filter(name__startswith='李').filter(content__contains="xx")

    return render(request, 'index.html', {"a": a})


def cindex(request):
    # if request.method == 'GET':
        a = request.GET.get('val')
        b = request.GET.get('vaq')
        c = request.GET.get('vah')
        # print(a)
        if a != 0:
            q = Stu.objects.filter(name__startswith=a,age__range=[int(b),int(c)])
            list  =[]
            for i in q:
                data={
                    'id':i.id,
                    'name':i.name,
                    'age':i.age
                }
                list.append(data)
            print(list)
                # print(JsonResponse(list,safe=False ))
        return JsonResponse(list,safe=False )


        # else:
            # return HttpResponse('aaa')
